|
|
|
|
|
|
|
Every time you execute the NewNote. Show method, another instance of the frmNote form is created. Each of these forms has associated with it all of the properties and events that you coded for the original form. |
|
|
|
|
|
|
|
|
Collections are used everywhere in Visual Basic. Using the MDI project, when you have more than one NewNote form displayed, you can work with them from the point of view of a collection or array of forms. Unlike arrays, collections do not have to be redimensioned every time an object member is added or removed. When working in Visual Basic, you can use two collections to track the forms and controls that you use in an application. The FORMS collection keeps track of every loaded form in an application, whereas the CONTROL collection keeps track of every control that is used within an application. In addition, you can use a third built-in object to define your own collections. Using the generic Collection class, you can create as many different instances of the Collection objects as you need in your application. |
|
|
|
|
|
|
|
|
The Collection object has three methods that you can use to add, remove, or access the objects in the collection. It also has one property that gives you the number of items in the collection. In the coming sections of this chapter, you will see how collections give you an easy way to access the objects of your application without writing large amounts of code. |
|
|
|
|
|
|
|
|
Many objects in Visual Basic have default collections associated with them. One such example is the TreeView control, which has a Nodes collection associated with it. Each item in the Nodes collection has its own related properties and methods. One of the better examples of an object model is the Data Access Object (DAO) model (see Figure 5.1). The classes of the DAO are organized into a hierarchy and in turn contain collections. Each collection belongs to the class above it in the hierarchy. |
|
|
|
|
|
|
|
|
Figure 5.1.
The classes, objects, and collections of the Data Access Object. |
|
|
|
|
|